﻿using System.Collections.Generic;
using UnityEngine;

public class RotateLights : MonoBehaviour
{
    //public float radius = 5f; // 圆的半径
    public float rotationSpeed = 100f; // 旋转速度，单位为度/秒

    //private List<GameObject> lights = new List<GameObject>();

    // Start is called before the first frame update
    void Start()
    {
        //for(int i = 0; i < transform.childCount; i++)
        //{
        //    Transform child = transform.GetChild(i);
        //    Quaternion currentRotation = child.rotation;
        //    Vector3 eulerAngles = currentRotation.eulerAngles;

        //    // 只改变z分量
        //    eulerAngles.z =360f/transform.childCount * i;

        //    // 设置新的旋转角度
        //    child.rotation = Quaternion.Euler(eulerAngles);
        //}
        //// 获取所有子物体
        //int numberOfLights = transform.childCount;
        //for (int i = 0; i < numberOfLights; i++)
        //{
        //    Transform childTransform = transform.GetChild(i);
        //    GameObject child = childTransform.gameObject;
        //    lights.Add(child);

        //    // 计算每根光线的位置
        //    float angle = i * (360f / numberOfLights);
        //    Vector3 position = new Vector3(radius * Mathf.Sin(angle * Mathf.Deg2Rad), 0, radius * Mathf.Cos(angle * Mathf.Deg2Rad));
        //    childTransform.localPosition = position;

        //    // 使光线的底部对准屏幕中心
        //    childTransform.LookAt(Vector3.zero);
        //}
    }

    // Update is called once per frame
    void Update()
    {
        // 获取当前旋转角度
        Quaternion currentRotation = transform.rotation;
        Vector3 eulerAngles = currentRotation.eulerAngles;

        // 只改变z分量
        eulerAngles.z += rotationSpeed * Time.deltaTime;

        // 设置新的旋转角度
        transform.rotation = Quaternion.Euler(eulerAngles);
    }
}
